﻿<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>选择课件</title>
    <!-- Bootstrap -->
    <link href="/ViewV5/CSS/bootstrap3.3.5/css/bootstrap.css" rel="stylesheet"> 
    <link href="/ViewV5/CSS/sass.css" rel="stylesheet" />
    <link href="/ViewV5/CSS/list.css" rel="stylesheet" />
    <link href="/ViewV5/CSS/default.css" rel="stylesheet" />
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="//cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="//cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        body {
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none; /*元素不能被选中*/
        }

        .isel {
            position: absolute;
            top: 18px;
            right: 10px;
            color: darkgoldenrod;
            font-size: 18px;
        }

        .pCard {
            min-width: 80px;
            text-align: center;
            margin: 8px 3px;
        }

            .pCard:hover .badge {
                visibility: visible;
            }

        .panel-body .badge {
            position: absolute;
            top: -5px;
            right: -6px;
            background-color: red;
            padding-left: 5px;
            padding-right: 5px;
            visibility: collapse;
        }
    </style>
</head>
<body ms-controller="KJGLSelect">
    <div class="nav-right" style="margin-left: 0">
        <div class="crm-box" style="margin:0px;">
            <div class="crm-filter-type clearfix">
                <h5 class="pull-left">课件类型：</h5>
                <ul class="clearfix">
                    <li class="pull-left">
                        <span ms-class-1="clicked:lbtype==''" ms-click="SelectType('')">全部</span>
                    </li>
                    <li class="pull-left">
                        <span ms-class-1="clicked:lbtype==1" ms-click="SelectType(1)">视频</span>
                        <span ms-class-1="clicked:lbtype==2" ms-click="SelectType(2)">文档</span>
                    </li>
                </ul>
            </div>
            <div class="crm-filter-type clearfix">
                <h5 class="pull-left">搜索：</h5>
                <div class="crm-common-search">
                    <input type="text" placeholder="搜索课件名称等" ms-duplex="search.SearchContent">
                    <button class="btn btn-primary glyphicon glyphicon-search" ms-click="GetKJGLList()"></button>
                </div>
            </div>
        </div>
        <div class="right-box" style="margin:0px;">
            <table class="ui-datatable table-hover table-responsive table-striped">
                <thead>
                    <tr>
                        <th class="text-center" style="width:60px;">
                            <div class="checkbox checkbox-inline" ms-click="SelKJGLAll(this)" style="padding-left:0px">
                                <div class="icheckbox_square-blue" id="inlineCheck2">
                                    <span class="iconfont icon-check ft12"></span>
                                </div>
                            </div>
                        </th>
                        <th>课件名称</th>
                        <th>主讲人</th>
                    </tr>
                </thead>
                <tbody>
                    <tr ms-repeat-kjdata="CommonData">
                        <td class="text-center">
                            <div class="checkbox checkbox-inline" ms-click="SelKJGLData(kjdata,this)" style="padding-left:0px">
                                <div class="icheckbox_square-blue" ms-class-1="checked:kjdata.issel" id="inlineCheck2">
                                    <span class="iconfont icon-check ft12"></span>
                                </div>
                            </div>
                        </td>
                        <td>{{kjdata.KJName}}</td>
                        <td>{{kjdata.KJZJR}}</td>
                    </tr>
                </tbody>
            </table>
            <div ms-if="Total>0" class="ui-datatable-page" id="pageDiv">
            </div>
        </div>
    </div>
    <script src="/ViewV5/JS/jquery-1.11.2.min.js"></script>
    <script src="/ViewV5/JS/laypage/laypage.js"></script>
    <script src="/ViewV5/CSS/bootstrap3.3.5/js/bootstrap.js"></script>
    <script src="/ViewV5/JS/avalon.js"></script>
    <script src="/ViewV5/JS/SZHLCommon.js?jsver=20160425"></script>
    <script>
        var model = avalon.define({
            $id: "KJGLSelect",
            checkval: ComFunJS.getQueryString("checkvalue") ? ComFunJS.getQueryString("checkvalue") : "",
            CommonData: [],
            lbtype: "",
            SearchContent: "",
            SelectType: function (type) {
                model.lbtype = type;
                model.GetKJGLList();
            },
            Total: "",
            page: 1,
            GetKJGLList: function (el) {
                $.getJSON('/API/VIEWAPI.ashx?Action=KCGL_GETPXKJLIST', { p: 1, P1: model.lbtype, Content: model.SearchContent }, function (resultData) {
                    if (resultData.ErrorMsg == "") {

                        resultData.Result.forEach(function (item) {
                            item.issel = false;
                            if (model.checkval) {
                                if (ComFunJS.FindItem(model.checkval.split(','), function (e) {
                         return e == item.ID;
                                }).length == 1) {
                                    item.issel = true;
                                    model.SelKJGL.push(item)
                                }
                            }
                        })
                        model.CommonData = resultData.Result;
                        model.Total = resultData.Result1;
                        laypage({
                            cont: 'pageDiv', //容器。值支持id名、原生dom对象，jquery对象。
                            pages: Math.ceil(parseInt(resultData.Result1) * 1.0 / 8), //通过后台拿到的总页数
                            curr: 1, //初始化当前页
                            skin: 'molv',
                            jump: function (e) { //触发分页后的回调
                                if (e.curr != model.page) {
                                    $.getJSON('/API/VIEWAPI.ashx?Action=PXGL_GETPXKJLIST', { p: e.curr, P1: model.lbtype, Content: model.SearchContent }, function (resultData) {
                                        if (resultData.ErrorMsg == "") {
                                            resultData.Result.forEach(function (item) {
                                                item.issel = false;
                                                if (model.checkval) {
                                                    if (ComFunJS.FindItem(model.checkval.split(','), function (e) {
                                                     return e == item.ID;
                                                    }).length == 1) {
                                                        item.issel = true;
                                                        model.SelKJGL.push(item)
                                                    }
                                                }
                                            })
                                            model.CommonData = resultData.Result;
                                        }
                                    })
                                    model.page = e.curr;
                                }
                            }
                        });
                    }
                })
            },
            SelKJGLData: function (item, dom) {

                item.issel = !item.issel;
                if (!item.issel) {
                    ComFunJS.DelItem(model.SelKJGL, "ID", item.ID)
                } else {
                    if (ComFunJS.FindItem(model.SelKJGL, function (e) {
                      return e.ID == item.ID;
                    }).length == 0) {
                        model.SelKJGL.push(item)
                    }
                }
            },
            SelKJGLAll: function (dom) {
                if (!$(dom).children().eq(0).hasClass("checked")) {
                    model.CommonData.forEach(function (item) {
                        item.issel = true;
                        if (ComFunJS.FindItem(model.SelKJGL, function (e) {
                   return e.ID == item.ID;
                        }).length == 0) {
                            model.SelKJGL.push(item)
                        }
                    })
                    $(dom).children().eq(0).addClass("checked");
                } else {
                    model.CommonData.forEach(function (item) {
                        item.issel = false;
                        ComFunJS.DelItem(model.SelKJGL, "ID", item.ID)

                    })
                    $(dom).children().eq(0).removeClass("checked");
                }

            },
            SelKJGL: [],//已选择用户
            DelSelKJGL: function (item) {
                ComFunJS.DelItem(model.SelKJGL, "ID", item.ID);
                model.CommonData.forEach(function (el) {
                    if (el.ID == item.ID) {
                        el.issel = false;
                    }
                })
            },
            CommonData: [],//查询用户结果
            render: function () {
            }
        })
        avalon.ready(function () { 
            model.GetKJGLList();
        })
        function GetSelKJData() {

            return model.SelKJGL.$model;

        }
    </script>
</body>
</html>